{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow import keras\n",
    "from tensorflow.keras import layers\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv('./dataset/Tweets.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_id</th>\n",
       "      <th>airline_sentiment</th>\n",
       "      <th>airline_sentiment_confidence</th>\n",
       "      <th>negativereason</th>\n",
       "      <th>negativereason_confidence</th>\n",
       "      <th>airline</th>\n",
       "      <th>airline_sentiment_gold</th>\n",
       "      <th>name</th>\n",
       "      <th>negativereason_gold</th>\n",
       "      <th>retweet_count</th>\n",
       "      <th>text</th>\n",
       "      <th>tweet_coord</th>\n",
       "      <th>tweet_created</th>\n",
       "      <th>tweet_location</th>\n",
       "      <th>user_timezone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>570306133677760513</td>\n",
       "      <td>neutral</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Virgin America</td>\n",
       "      <td>NaN</td>\n",
       "      <td>cairdin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>@VirginAmerica What @dhepburn said.</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015-02-24 11:35:52 -0800</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Eastern Time (US &amp; Canada)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>570301130888122368</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.3486</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>Virgin America</td>\n",
       "      <td>NaN</td>\n",
       "      <td>jnardino</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>@VirginAmerica plus you've added commercials t...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015-02-24 11:15:59 -0800</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pacific Time (US &amp; Canada)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>570301083672813571</td>\n",
       "      <td>neutral</td>\n",
       "      <td>0.6837</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Virgin America</td>\n",
       "      <td>NaN</td>\n",
       "      <td>yvonnalynn</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>@VirginAmerica I didn't today... Must mean I n...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015-02-24 11:15:48 -0800</td>\n",
       "      <td>Lets Play</td>\n",
       "      <td>Central Time (US &amp; Canada)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>570301031407624196</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>Bad Flight</td>\n",
       "      <td>0.7033</td>\n",
       "      <td>Virgin America</td>\n",
       "      <td>NaN</td>\n",
       "      <td>jnardino</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>@VirginAmerica it's really aggressive to blast...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015-02-24 11:15:36 -0800</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pacific Time (US &amp; Canada)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>570300817074462722</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>Can't Tell</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>Virgin America</td>\n",
       "      <td>NaN</td>\n",
       "      <td>jnardino</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>@VirginAmerica and it's a really big bad thing...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015-02-24 11:14:45 -0800</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pacific Time (US &amp; Canada)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             tweet_id airline_sentiment  airline_sentiment_confidence  \\\n",
       "0  570306133677760513           neutral                        1.0000   \n",
       "1  570301130888122368          positive                        0.3486   \n",
       "2  570301083672813571           neutral                        0.6837   \n",
       "3  570301031407624196          negative                        1.0000   \n",
       "4  570300817074462722          negative                        1.0000   \n",
       "\n",
       "  negativereason  negativereason_confidence         airline  \\\n",
       "0            NaN                        NaN  Virgin America   \n",
       "1            NaN                     0.0000  Virgin America   \n",
       "2            NaN                        NaN  Virgin America   \n",
       "3     Bad Flight                     0.7033  Virgin America   \n",
       "4     Can't Tell                     1.0000  Virgin America   \n",
       "\n",
       "  airline_sentiment_gold        name negativereason_gold  retweet_count  \\\n",
       "0                    NaN     cairdin                 NaN              0   \n",
       "1                    NaN    jnardino                 NaN              0   \n",
       "2                    NaN  yvonnalynn                 NaN              0   \n",
       "3                    NaN    jnardino                 NaN              0   \n",
       "4                    NaN    jnardino                 NaN              0   \n",
       "\n",
       "                                                text tweet_coord  \\\n",
       "0                @VirginAmerica What @dhepburn said.         NaN   \n",
       "1  @VirginAmerica plus you've added commercials t...         NaN   \n",
       "2  @VirginAmerica I didn't today... Must mean I n...         NaN   \n",
       "3  @VirginAmerica it's really aggressive to blast...         NaN   \n",
       "4  @VirginAmerica and it's a really big bad thing...         NaN   \n",
       "\n",
       "               tweet_created tweet_location               user_timezone  \n",
       "0  2015-02-24 11:35:52 -0800            NaN  Eastern Time (US & Canada)  \n",
       "1  2015-02-24 11:15:59 -0800            NaN  Pacific Time (US & Canada)  \n",
       "2  2015-02-24 11:15:48 -0800      Lets Play  Central Time (US & Canada)  \n",
       "3  2015-02-24 11:15:36 -0800            NaN  Pacific Time (US & Canada)  \n",
       "4  2015-02-24 11:14:45 -0800            NaN  Pacific Time (US & Canada)  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data[['airline_sentiment', 'text']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['neutral', 'positive', 'negative'], dtype=object)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.airline_sentiment.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "negative    9178\n",
       "neutral     3099\n",
       "positive    2363\n",
       "Name: airline_sentiment, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.airline_sentiment.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_p = data[data.airline_sentiment == 'positive']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_n = data[data.airline_sentiment == 'negative']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_n = data_n.iloc[:len(data_p)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2363, 2363)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data_n), len(data_p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.concat([data_n, data_p])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.sample(len(data))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['review'] = (data.airline_sentiment == 'positive').astype('int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "del data['airline_sentiment']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "tf.keras.layers.Embedding  把文本向量化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "token = re.compile('[A-Za-z]+|[!?,.()]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def reg_text(text):\n",
    "    new_text = token.findall(text)\n",
    "    new_text = [word.lower() for word in new_text]\n",
    "    return new_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['text'] = data.text.apply(reg_text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_set = set()\n",
    "for text in data.text:\n",
    "    for word in text:\n",
    "        word_set.add(word) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7101"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_word = len(word_set) + 1\n",
    "max_word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_list = list(word_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4272"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_list.index('spending')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_index =  dict((word, word_list.index(word) + 1) for word in word_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'travelzoo': 1,\n",
       " 'hearts': 2,\n",
       " 'junction': 3,\n",
       " 'cking': 4,\n",
       " 'lrfo': 5,\n",
       " 'fair': 6,\n",
       " 'hdn': 7,\n",
       " 'dai': 8,\n",
       " 'intended': 9,\n",
       " 'squished': 10,\n",
       " 'speaking': 11,\n",
       " 'diego': 12,\n",
       " 'carseat': 13,\n",
       " 'jedediah': 14,\n",
       " 'firstclass': 15,\n",
       " 'from': 16,\n",
       " 'enoughisenough': 17,\n",
       " 'aopdtsq': 18,\n",
       " 'lil': 19,\n",
       " 'experienced': 20,\n",
       " 'restrm': 21,\n",
       " 'virginamerica': 22,\n",
       " 'thisiscoach': 23,\n",
       " 'qualified': 24,\n",
       " 'dqjl': 25,\n",
       " 'branding': 26,\n",
       " 'program': 27,\n",
       " 'makingthingseasy': 28,\n",
       " 'destinationdragons': 29,\n",
       " 'winters': 30,\n",
       " 'embody': 31,\n",
       " 'repeatedly': 32,\n",
       " 'frankly': 33,\n",
       " 'waitingforbags': 34,\n",
       " 'shampoo': 35,\n",
       " 'disrespected': 36,\n",
       " 'dontmakemebeg': 37,\n",
       " 'celebrate': 38,\n",
       " 'lsn': 39,\n",
       " 'liable': 40,\n",
       " 'beanie': 41,\n",
       " 'trash': 42,\n",
       " 'normal': 43,\n",
       " 'cutest': 44,\n",
       " 'lea': 45,\n",
       " 'ellahenderson': 46,\n",
       " 'cnn': 47,\n",
       " 'virgin': 48,\n",
       " 'hbsj': 49,\n",
       " 'performance': 50,\n",
       " 'acknowledgement': 51,\n",
       " 'nogate': 52,\n",
       " 'delivery': 53,\n",
       " 'providing': 54,\n",
       " 'hiccups': 55,\n",
       " 'intuitlife': 56,\n",
       " 'americanisbetter': 57,\n",
       " 'overcharge': 58,\n",
       " 'makeup': 59,\n",
       " 'ptfo': 60,\n",
       " 'representatives': 61,\n",
       " 'direct': 62,\n",
       " 'bourbon': 63,\n",
       " 'zfqmpgxvs': 64,\n",
       " 'behaves': 65,\n",
       " 'going': 66,\n",
       " 'flies': 67,\n",
       " 'presenting': 68,\n",
       " 'takemeback': 69,\n",
       " 'flying': 70,\n",
       " 'yeah': 71,\n",
       " 'claim': 72,\n",
       " 'unprecedented': 73,\n",
       " 'announcement': 74,\n",
       " 'qdw': 75,\n",
       " 'aegeanairlines': 76,\n",
       " 'frustration': 77,\n",
       " 'frustrated': 78,\n",
       " 'cxp': 79,\n",
       " 'lasairport': 80,\n",
       " 'ivgpzsjtkw': 81,\n",
       " 'to': 82,\n",
       " 'clifton': 83,\n",
       " 'logging': 84,\n",
       " 'zouowgv': 85,\n",
       " 'kindness': 86,\n",
       " 'disappeared': 87,\n",
       " 'early': 88,\n",
       " 'badbadbad': 89,\n",
       " 'include': 90,\n",
       " 'jon': 91,\n",
       " 'much': 92,\n",
       " 'ozs': 93,\n",
       " 'counter': 94,\n",
       " 'nomorecheckedbags': 95,\n",
       " 'bundle': 96,\n",
       " 'computers': 97,\n",
       " 'understaffed': 98,\n",
       " 'joanna': 99,\n",
       " 'every': 100,\n",
       " 'lose': 101,\n",
       " 'acts': 102,\n",
       " 'spousal': 103,\n",
       " 'telaviv': 104,\n",
       " 'many': 105,\n",
       " 'teamspirit': 106,\n",
       " 'abt': 107,\n",
       " 'unsure': 108,\n",
       " 'definition': 109,\n",
       " 'boat': 110,\n",
       " 'experiencing': 111,\n",
       " 'sked': 112,\n",
       " 'apollochplayers': 113,\n",
       " 'mikes': 114,\n",
       " 'channels': 115,\n",
       " 'cudtomers': 116,\n",
       " 'albany': 117,\n",
       " 'gentleman': 118,\n",
       " 'tiredofwaiting': 119,\n",
       " 'aren': 120,\n",
       " 'kqlhvap': 121,\n",
       " 'expect': 122,\n",
       " 'temps': 123,\n",
       " 'cousin': 124,\n",
       " 'practices': 125,\n",
       " 'myers': 126,\n",
       " 'fsd': 127,\n",
       " 'pattern': 128,\n",
       " 'difficulties': 129,\n",
       " 'swaculture': 130,\n",
       " 'incoming': 131,\n",
       " 'umm': 132,\n",
       " 'energy': 133,\n",
       " 'advisory': 134,\n",
       " 'faanews': 135,\n",
       " 'donut': 136,\n",
       " 'erased': 137,\n",
       " 'dreampath': 138,\n",
       " 'hire': 139,\n",
       " 'four': 140,\n",
       " 'events': 141,\n",
       " 'preventative': 142,\n",
       " 'mosaicmecrazy': 143,\n",
       " 'luvswa': 144,\n",
       " 'piggy': 145,\n",
       " 'corp': 146,\n",
       " 'dnx': 147,\n",
       " 'luggages': 148,\n",
       " 'continue': 149,\n",
       " 'rule': 150,\n",
       " 'robotic': 151,\n",
       " 'pointed': 152,\n",
       " 'az': 153,\n",
       " 'kms': 154,\n",
       " 'cyberattack': 155,\n",
       " 'pykfvrq': 156,\n",
       " 'allowed': 157,\n",
       " 'verbal': 158,\n",
       " 'code': 159,\n",
       " 'baldordash': 160,\n",
       " 'snobby': 161,\n",
       " 'tripping': 162,\n",
       " 'la': 163,\n",
       " 'these': 164,\n",
       " 'carryon': 165,\n",
       " 'house': 166,\n",
       " 'club': 167,\n",
       " 'choice': 168,\n",
       " 'annoyed': 169,\n",
       " 'digging': 170,\n",
       " 'cellphone': 171,\n",
       " 'sjc': 172,\n",
       " 'sides': 173,\n",
       " 'english': 174,\n",
       " 'lowered': 175,\n",
       " 'shipped': 176,\n",
       " 'expedia': 177,\n",
       " 'remembering': 178,\n",
       " 'led': 179,\n",
       " 'product': 180,\n",
       " 'wasn': 181,\n",
       " 'rockinwellness': 182,\n",
       " 'vp': 183,\n",
       " 'personable': 184,\n",
       " 'ksgcq': 185,\n",
       " 'leah': 186,\n",
       " 'cana': 187,\n",
       " 'biggest': 188,\n",
       " 'saved': 189,\n",
       " 'forum': 190,\n",
       " 'spoiled': 191,\n",
       " 'added': 192,\n",
       " 'lt': 193,\n",
       " 'zz': 194,\n",
       " 'nrt': 195,\n",
       " 'airtahitinui': 196,\n",
       " 'stated': 197,\n",
       " 'inexcusable': 198,\n",
       " 'cheek': 199,\n",
       " 'shoes': 200,\n",
       " 'ja': 201,\n",
       " 'saying': 202,\n",
       " 'mktg': 203,\n",
       " 'keeps': 204,\n",
       " 'sabe': 205,\n",
       " 'xaizw': 206,\n",
       " 'accountability': 207,\n",
       " 'hollywood': 208,\n",
       " 'rbn': 209,\n",
       " 'suprise': 210,\n",
       " 'sonyasloanmd': 211,\n",
       " 'combined': 212,\n",
       " 'exist': 213,\n",
       " 'knew': 214,\n",
       " 'simonroesner': 215,\n",
       " 'experience': 216,\n",
       " 'sciencebehindtheexperience': 217,\n",
       " 'ewr': 218,\n",
       " 'misconnected': 219,\n",
       " 'booze': 220,\n",
       " 'accepting': 221,\n",
       " 'faster': 222,\n",
       " 'lednocdqee': 223,\n",
       " 'hug': 224,\n",
       " 'website': 225,\n",
       " 'plan': 226,\n",
       " 'friendlyteam': 227,\n",
       " 'problem': 228,\n",
       " 'ended': 229,\n",
       " 'quickie': 230,\n",
       " 'lax': 231,\n",
       " 'nice': 232,\n",
       " 'teamusa': 233,\n",
       " 'bom': 234,\n",
       " 'pyalebgkjt': 235,\n",
       " 'atlanta': 236,\n",
       " 'znfwkkwp': 237,\n",
       " 'yall': 238,\n",
       " 'lucycat': 239,\n",
       " 'louisville': 240,\n",
       " 'zfroinpszi': 241,\n",
       " 'traditions': 242,\n",
       " 'bp': 243,\n",
       " 'noneother': 244,\n",
       " 'deplaning': 245,\n",
       " 'paris': 246,\n",
       " 'flightly': 247,\n",
       " 'white': 248,\n",
       " 'rapid': 249,\n",
       " 'deserves': 250,\n",
       " 'tkvcmhbpim': 251,\n",
       " 'wantmymoneyback': 252,\n",
       " 'freaked': 253,\n",
       " 'cannedtweet': 254,\n",
       " 'engagement': 255,\n",
       " 'flyitforward': 256,\n",
       " 'awful': 257,\n",
       " 'realtime': 258,\n",
       " 'refusing': 259,\n",
       " 'sleeping': 260,\n",
       " 'worked': 261,\n",
       " 'qan': 262,\n",
       " 'his': 263,\n",
       " 'bonuses': 264,\n",
       " 'curious': 265,\n",
       " 'size': 266,\n",
       " 'bringbackrealstaff': 267,\n",
       " 'fouty': 268,\n",
       " 'disspointed': 269,\n",
       " 'origin': 270,\n",
       " 'seriousness': 271,\n",
       " 'turrible': 272,\n",
       " 'sheesh': 273,\n",
       " 'desk': 274,\n",
       " 'stars': 275,\n",
       " 'throughout': 276,\n",
       " 'innovation': 277,\n",
       " 'sundayfunday': 278,\n",
       " 'main': 279,\n",
       " 'absolutely': 280,\n",
       " 'honululu': 281,\n",
       " 'philly': 282,\n",
       " 'awake': 283,\n",
       " 'absolute': 284,\n",
       " 'winterstorm': 285,\n",
       " 'cory': 286,\n",
       " 'lie': 287,\n",
       " 'disgutedindenver': 288,\n",
       " 'xx': 289,\n",
       " 'operator': 290,\n",
       " 'calgary': 291,\n",
       " 'headaches': 292,\n",
       " 'cousins': 293,\n",
       " 'rent': 294,\n",
       " 'zgoqoxjbqy': 295,\n",
       " 'school': 296,\n",
       " 'ball': 297,\n",
       " 'tolerable': 298,\n",
       " 'movies': 299,\n",
       " 'istanbul': 300,\n",
       " 'kevin': 301,\n",
       " 'impacts': 302,\n",
       " 'tlpbaupik': 303,\n",
       " 'gguaa': 304,\n",
       " 'created': 305,\n",
       " 'indicates': 306,\n",
       " 'announcements': 307,\n",
       " 'daysofunitedfailures': 308,\n",
       " 'dmb': 309,\n",
       " 'slots': 310,\n",
       " 'obnoxious': 311,\n",
       " 'formed': 312,\n",
       " 'companions': 313,\n",
       " 'spite': 314,\n",
       " 'den': 315,\n",
       " 'ragncw': 316,\n",
       " 'elbows': 317,\n",
       " 'adve': 318,\n",
       " 'aspen': 319,\n",
       " 'madrid': 320,\n",
       " 'fix': 321,\n",
       " 'tamara': 322,\n",
       " 'moon': 323,\n",
       " 'men': 324,\n",
       " 'newplanesmell': 325,\n",
       " 'maintenance': 326,\n",
       " 'pie': 327,\n",
       " 'hunt': 328,\n",
       " 'reassign': 329,\n",
       " 'building': 330,\n",
       " 'suggest': 331,\n",
       " 'awards': 332,\n",
       " 'jetbae': 333,\n",
       " 'flysaa': 334,\n",
       " 'mypompanobeach': 335,\n",
       " 'grouchy': 336,\n",
       " 'cool': 337,\n",
       " 'went': 338,\n",
       " 'heard': 339,\n",
       " 'yxn': 340,\n",
       " 'passbook': 341,\n",
       " 'anamarketers': 342,\n",
       " 'feelingtheluv': 343,\n",
       " 'contentmarketing': 344,\n",
       " 'cookies': 345,\n",
       " 'yay': 346,\n",
       " 'aus': 347,\n",
       " 'gettin': 348,\n",
       " 'stlouis': 349,\n",
       " 'jacqueline': 350,\n",
       " 'write': 351,\n",
       " 'haul': 352,\n",
       " 'handed': 353,\n",
       " 'concentrate': 354,\n",
       " 'ranting': 355,\n",
       " 'mumbai': 356,\n",
       " 'ripped': 357,\n",
       " 'interrupted': 358,\n",
       " 'z': 359,\n",
       " 'vomit': 360,\n",
       " 'srsly': 361,\n",
       " 'reservation': 362,\n",
       " 'gopro': 363,\n",
       " 'disastrous': 364,\n",
       " 'saw': 365,\n",
       " 'usual': 366,\n",
       " 'marks': 367,\n",
       " 'weekends': 368,\n",
       " 'travellers': 369,\n",
       " 'alwaysdelayed': 370,\n",
       " 'driver': 371,\n",
       " 'udub': 372,\n",
       " 'stranded': 373,\n",
       " 'shouldnt': 374,\n",
       " 'letter': 375,\n",
       " 'die': 376,\n",
       " 'list': 377,\n",
       " 'emaleesugano': 378,\n",
       " 'baggage': 379,\n",
       " 'facebook': 380,\n",
       " 'metal': 381,\n",
       " 'jfps': 382,\n",
       " 'unitedagainstunited': 383,\n",
       " 'bitch': 384,\n",
       " 'overcharged': 385,\n",
       " 'thanks': 386,\n",
       " 'faves': 387,\n",
       " 'full': 388,\n",
       " 'attendees': 389,\n",
       " 'turns': 390,\n",
       " 'mere': 391,\n",
       " 'diverted': 392,\n",
       " 'hubby': 393,\n",
       " 'illegal': 394,\n",
       " 'tracking': 395,\n",
       " 'adopted': 396,\n",
       " 'clt': 397,\n",
       " 'marie': 398,\n",
       " 'sbn': 399,\n",
       " 'no': 400,\n",
       " 'packed': 401,\n",
       " 'rikrik': 402,\n",
       " 'char': 403,\n",
       " 'holidays': 404,\n",
       " 'published': 405,\n",
       " 'astounds': 406,\n",
       " 'books': 407,\n",
       " 'ethics': 408,\n",
       " 'pujvcelng': 409,\n",
       " 'bold': 410,\n",
       " 'value': 411,\n",
       " 'city': 412,\n",
       " 'tea': 413,\n",
       " 'expowest': 414,\n",
       " 'antonio': 415,\n",
       " 'pesky': 416,\n",
       " 'idols': 417,\n",
       " 'dep': 418,\n",
       " 'season': 419,\n",
       " 'taxi': 420,\n",
       " 'darn': 421,\n",
       " 'organization': 422,\n",
       " 'ceases': 423,\n",
       " 'incubator': 424,\n",
       " 'talking': 425,\n",
       " 'numerous': 426,\n",
       " 'dresparkles': 427,\n",
       " 'sprinkled': 428,\n",
       " 'westagard': 429,\n",
       " 'post': 430,\n",
       " 'restriction': 431,\n",
       " 'heavenlychc': 432,\n",
       " 'southwest': 433,\n",
       " 'iadore': 434,\n",
       " 'bethonors': 435,\n",
       " 'jk': 436,\n",
       " 'tall': 437,\n",
       " 'preexisting': 438,\n",
       " 'crewmembers': 439,\n",
       " 'miscounting': 440,\n",
       " 'cant': 441,\n",
       " 'fyi': 442,\n",
       " 'bked': 443,\n",
       " 'devices': 444,\n",
       " 'heidimacey': 445,\n",
       " 'scl': 446,\n",
       " 'messaged': 447,\n",
       " 'threatens': 448,\n",
       " 'angrycustomer': 449,\n",
       " 'hpn': 450,\n",
       " 'fares': 451,\n",
       " 'beverage': 452,\n",
       " 'falling': 453,\n",
       " 'trueblue': 454,\n",
       " 'pigs': 455,\n",
       " 'piece': 456,\n",
       " 'rebook': 457,\n",
       " 'xcvqxykg': 458,\n",
       " 'including': 459,\n",
       " 'happytweet': 460,\n",
       " 'disgrace': 461,\n",
       " 'important': 462,\n",
       " 'hostage': 463,\n",
       " 'lh': 464,\n",
       " 'sandwich': 465,\n",
       " 'msg': 466,\n",
       " 'senses': 467,\n",
       " 'ourguest': 468,\n",
       " 'bounced': 469,\n",
       " 'liza': 470,\n",
       " 'deaf': 471,\n",
       " 'nj': 472,\n",
       " 'beating': 473,\n",
       " 'ongoing': 474,\n",
       " 'accidents': 475,\n",
       " 'hand': 476,\n",
       " 'sass': 477,\n",
       " 'directtv': 478,\n",
       " 'pumped': 479,\n",
       " 'designer': 480,\n",
       " 'fc': 481,\n",
       " 'promising': 482,\n",
       " 'ar': 483,\n",
       " 'would': 484,\n",
       " 'wmass': 485,\n",
       " 'fashioned': 486,\n",
       " 'rtr': 487,\n",
       " 'kbhym': 488,\n",
       " 'sunglasses': 489,\n",
       " 'newly': 490,\n",
       " 'londonfashionweek': 491,\n",
       " 'show': 492,\n",
       " 'greetings': 493,\n",
       " 'businesstravel': 494,\n",
       " 'boston': 495,\n",
       " 'flysw': 496,\n",
       " 'do': 497,\n",
       " 'passion': 498,\n",
       " 'nocharge': 499,\n",
       " 'elliott': 500,\n",
       " 'balancing': 501,\n",
       " 'hut': 502,\n",
       " 'incompetent': 503,\n",
       " 'strives': 504,\n",
       " 'bgm': 505,\n",
       " 'aggressive': 506,\n",
       " 'after': 507,\n",
       " 'miaa': 508,\n",
       " 'function': 509,\n",
       " 'hopeful': 510,\n",
       " 'delays': 511,\n",
       " 'travels': 512,\n",
       " 'mpwnc': 513,\n",
       " 'deserved': 514,\n",
       " 'story': 515,\n",
       " 'stopped': 516,\n",
       " 'ain': 517,\n",
       " 'ruin': 518,\n",
       " 'sllyibe': 519,\n",
       " 'jkzr': 520,\n",
       " 'remorse': 521,\n",
       " 'operate': 522,\n",
       " 'dnstitrzwy': 523,\n",
       " 'handle': 524,\n",
       " 'nywr': 525,\n",
       " 'dullessucks': 526,\n",
       " 'we': 527,\n",
       " 'latrice': 528,\n",
       " 'helene': 529,\n",
       " 'vrfhjht': 530,\n",
       " 'cnxns': 531,\n",
       " 'ruth': 532,\n",
       " 'filling': 533,\n",
       " 'pedophile': 534,\n",
       " 'removed': 535,\n",
       " 'routine': 536,\n",
       " 'fttfyfmvco': 537,\n",
       " 'fll': 538,\n",
       " 'lo': 539,\n",
       " 'heathrow': 540,\n",
       " 'cheated': 541,\n",
       " 'intentionally': 542,\n",
       " 'tyr': 543,\n",
       " 'method': 544,\n",
       " 'represents': 545,\n",
       " 'frequency': 546,\n",
       " 'sneaky': 547,\n",
       " 'happycustomer': 548,\n",
       " 'iha': 549,\n",
       " 'innp': 550,\n",
       " 'suit': 551,\n",
       " 'brandssayingbae': 552,\n",
       " 'screws': 553,\n",
       " 'ps': 554,\n",
       " 'stressful': 555,\n",
       " 'accounts': 556,\n",
       " 'pnoav': 557,\n",
       " 'services': 558,\n",
       " 'lap': 559,\n",
       " 'earlier': 560,\n",
       " 'littlebirds': 561,\n",
       " 'kathrynsotelo': 562,\n",
       " 'round': 563,\n",
       " 'lga': 564,\n",
       " 'rim': 565,\n",
       " 'swapped': 566,\n",
       " 'chatted': 567,\n",
       " 'owohd': 568,\n",
       " 'aboard': 569,\n",
       " 'exp': 570,\n",
       " 'supp': 571,\n",
       " 'daystogo': 572,\n",
       " 'burbank': 573,\n",
       " 'get': 574,\n",
       " 'plenty': 575,\n",
       " 'forgetting': 576,\n",
       " 'crash': 577,\n",
       " 'lai': 578,\n",
       " 'slept': 579,\n",
       " 'loeco': 580,\n",
       " 'giant': 581,\n",
       " 'acknowledge': 582,\n",
       " 'herman': 583,\n",
       " 'award': 584,\n",
       " 'hour': 585,\n",
       " 'fq': 586,\n",
       " 'preparations': 587,\n",
       " 'dbcvepn': 588,\n",
       " 'drunk': 589,\n",
       " 'degree': 590,\n",
       " 'maintain': 591,\n",
       " 'pacific': 592,\n",
       " 'that': 593,\n",
       " 'tells': 594,\n",
       " 'present': 595,\n",
       " 'annricord': 596,\n",
       " 'stbernard': 597,\n",
       " 'rest': 598,\n",
       " 'phones': 599,\n",
       " 'papers': 600,\n",
       " 'tags': 601,\n",
       " 'yg': 602,\n",
       " 'skis': 603,\n",
       " 'shattered': 604,\n",
       " 'worstairlineever': 605,\n",
       " 'subscribe': 606,\n",
       " 'clincher': 607,\n",
       " 'wasappreciated': 608,\n",
       " 'maine': 609,\n",
       " 'significantly': 610,\n",
       " 'segment': 611,\n",
       " 'long': 612,\n",
       " 'happiness': 613,\n",
       " 'iqu': 614,\n",
       " 'adams': 615,\n",
       " 'blackhistorymonth': 616,\n",
       " 'shots': 617,\n",
       " 'humored': 618,\n",
       " 'best': 619,\n",
       " 'wrong': 620,\n",
       " 'ppva': 621,\n",
       " 'total': 622,\n",
       " 'comfort': 623,\n",
       " 'dark': 624,\n",
       " 'married': 625,\n",
       " 'regional': 626,\n",
       " 'confirming': 627,\n",
       " 'leaves': 628,\n",
       " 'catching': 629,\n",
       " 'airport': 630,\n",
       " 'skiing': 631,\n",
       " 'responds': 632,\n",
       " 'ferrissalameh': 633,\n",
       " 'load': 634,\n",
       " 'javascript': 635,\n",
       " 'congratulations': 636,\n",
       " 'capable': 637,\n",
       " 'perk': 638,\n",
       " 'huh': 639,\n",
       " 'imnp': 640,\n",
       " 'minutes': 641,\n",
       " 'exciting': 642,\n",
       " 'jetred': 643,\n",
       " 'badcustomerservice': 644,\n",
       " 'superben': 645,\n",
       " 'change': 646,\n",
       " 'pia': 647,\n",
       " 'consistency': 648,\n",
       " 'attentiveness': 649,\n",
       " 'arrogant': 650,\n",
       " 'question': 651,\n",
       " 'convenience': 652,\n",
       " 'request': 653,\n",
       " 'destination': 654,\n",
       " 'management': 655,\n",
       " 'responsive': 656,\n",
       " 'fgrbpazsix': 657,\n",
       " 'huston': 658,\n",
       " 'anotherdisappointment': 659,\n",
       " 'departure': 660,\n",
       " 'dishonoring': 661,\n",
       " 'egregious': 662,\n",
       " 'hats': 663,\n",
       " 'aesthetics': 664,\n",
       " 'outsourcing': 665,\n",
       " 'displaced': 666,\n",
       " 'ads': 667,\n",
       " 'fell': 668,\n",
       " 'toothpaste': 669,\n",
       " 'misplaced': 670,\n",
       " 'kat': 671,\n",
       " 'rushed': 672,\n",
       " 'logan': 673,\n",
       " 'em': 674,\n",
       " 'inquire': 675,\n",
       " 'logs': 676,\n",
       " 'underserved': 677,\n",
       " 'apt': 678,\n",
       " 'disgruntled': 679,\n",
       " 'outage': 680,\n",
       " 'cleaning': 681,\n",
       " 'charleston': 682,\n",
       " 'switching': 683,\n",
       " 'tonight': 684,\n",
       " 'disappoints': 685,\n",
       " 'active': 686,\n",
       " 'company': 687,\n",
       " 'ski': 688,\n",
       " 'nyfw': 689,\n",
       " 'contacted': 690,\n",
       " 'tripitpro': 691,\n",
       " 'begrudgingly': 692,\n",
       " 'hands': 693,\n",
       " 'soft': 694,\n",
       " 'drinks': 695,\n",
       " 'returning': 696,\n",
       " 'prior': 697,\n",
       " 'splitting': 698,\n",
       " 'ask': 699,\n",
       " 'bur': 700,\n",
       " 'notify': 701,\n",
       " 'practice': 702,\n",
       " 'ways': 703,\n",
       " 'austin': 704,\n",
       " 'hot': 705,\n",
       " 'rentals': 706,\n",
       " 'gary': 707,\n",
       " 'vincenzolandino': 708,\n",
       " 'angeles': 709,\n",
       " 'complained': 710,\n",
       " 'contd': 711,\n",
       " 'live': 712,\n",
       " 'freddieawards': 713,\n",
       " 'refreshments': 714,\n",
       " 'colored': 715,\n",
       " 'kkedjnrtwo': 716,\n",
       " 'trappedhouston': 717,\n",
       " 'frame': 718,\n",
       " 'standard': 719,\n",
       " 'blueheros': 720,\n",
       " 'suggestions': 721,\n",
       " 'transactional': 722,\n",
       " 'ix': 723,\n",
       " 'athletes': 724,\n",
       " 'rockies': 725,\n",
       " 'otherwise': 726,\n",
       " 'complaining': 727,\n",
       " 'npxb': 728,\n",
       " 'poisoning': 729,\n",
       " 'avail': 730,\n",
       " 'icing': 731,\n",
       " 'lining': 732,\n",
       " 'jlhalldc': 733,\n",
       " 'chk': 734,\n",
       " 'complain': 735,\n",
       " 'igkogywksr': 736,\n",
       " 'wsj': 737,\n",
       " 'odds': 738,\n",
       " 'luvin': 739,\n",
       " 'saipan': 740,\n",
       " 'cust': 741,\n",
       " 'aviv': 742,\n",
       " 'reply': 743,\n",
       " 'fete': 744,\n",
       " 'designated': 745,\n",
       " 'pairs': 746,\n",
       " 'alive': 747,\n",
       " 'ut': 748,\n",
       " 'bins': 749,\n",
       " 'on': 750,\n",
       " 'traveling': 751,\n",
       " 'beers': 752,\n",
       " 'awkward': 753,\n",
       " 'cus': 754,\n",
       " 'servicefail': 755,\n",
       " 'august': 756,\n",
       " 'fucked': 757,\n",
       " 'kevinswan': 758,\n",
       " 'guessing': 759,\n",
       " 'uncontrollably': 760,\n",
       " 'pants': 761,\n",
       " 'blacklivesmatter': 762,\n",
       " 'sourhwest': 763,\n",
       " 'preferred': 764,\n",
       " 'insulted': 765,\n",
       " 'chairman': 766,\n",
       " 'payment': 767,\n",
       " 'pto': 768,\n",
       " 'voided': 769,\n",
       " 'their': 770,\n",
       " 'look': 771,\n",
       " 'plain': 772,\n",
       " 'cart': 773,\n",
       " 'careyon': 774,\n",
       " 'fa': 775,\n",
       " 'attentive': 776,\n",
       " 'moveaboutthecountry': 777,\n",
       " 'demonstration': 778,\n",
       " 'peer': 779,\n",
       " 'someone': 780,\n",
       " 'final': 781,\n",
       " 'trick': 782,\n",
       " 'spring': 783,\n",
       " 'least': 784,\n",
       " 'sammi': 785,\n",
       " 'changed': 786,\n",
       " 'bro': 787,\n",
       " 'bs': 788,\n",
       " 'reduce': 789,\n",
       " 'advertise': 790,\n",
       " 'digital': 791,\n",
       " 'graphic': 792,\n",
       " 'electrical': 793,\n",
       " 'beware': 794,\n",
       " 'automobiles': 795,\n",
       " 'used': 796,\n",
       " 'calls': 797,\n",
       " 'software': 798,\n",
       " 'buddies': 799,\n",
       " 'food': 800,\n",
       " 'gz': 801,\n",
       " 'sounds': 802,\n",
       " 'understatement': 803,\n",
       " 'travelocity': 804,\n",
       " 'exception': 805,\n",
       " 'video': 806,\n",
       " 'submitted': 807,\n",
       " 'hopeless': 808,\n",
       " 'guy': 809,\n",
       " 'were': 810,\n",
       " 'smiles': 811,\n",
       " 'elsewhere': 812,\n",
       " 'comped': 813,\n",
       " 'auto': 814,\n",
       " 'banana': 815,\n",
       " 'amounts': 816,\n",
       " 'opposed': 817,\n",
       " 'usairway': 818,\n",
       " 'geiger': 819,\n",
       " 'osjz': 820,\n",
       " 'infant': 821,\n",
       " 'scary': 822,\n",
       " 'robbing': 823,\n",
       " 'milan': 824,\n",
       " 'sjveelween': 825,\n",
       " 'covering': 826,\n",
       " 'police': 827,\n",
       " 'town': 828,\n",
       " 'instructed': 829,\n",
       " 'vftuyjh': 830,\n",
       " 'discount': 831,\n",
       " 'covered': 832,\n",
       " 'enjoy': 833,\n",
       " 'fo': 834,\n",
       " 'bosnia': 835,\n",
       " 'cruel': 836,\n",
       " 'turning': 837,\n",
       " 'cabo': 838,\n",
       " 'needtocatchmynextflight': 839,\n",
       " 'opening': 840,\n",
       " 'occurred': 841,\n",
       " 'sam': 842,\n",
       " 'typical': 843,\n",
       " 'calling': 844,\n",
       " 'golf': 845,\n",
       " 'living': 846,\n",
       " 'make': 847,\n",
       " 'wt': 848,\n",
       " 'v': 849,\n",
       " 'thanksdave': 850,\n",
       " 'deane': 851,\n",
       " 'avrtowtyzk': 852,\n",
       " 'qjbcv': 853,\n",
       " 'fyvrfn': 854,\n",
       " 'terminals': 855,\n",
       " 'severely': 856,\n",
       " 'proj': 857,\n",
       " 'retweeted': 858,\n",
       " 'those': 859,\n",
       " 'espinosa': 860,\n",
       " 'beats': 861,\n",
       " 'game': 862,\n",
       " 'hj': 863,\n",
       " 'entire': 864,\n",
       " 'deicing': 865,\n",
       " 'mammoth': 866,\n",
       " 'silence': 867,\n",
       " 'evry': 868,\n",
       " 'welcome': 869,\n",
       " 'medal': 870,\n",
       " 'partnership': 871,\n",
       " 'roll': 872,\n",
       " 'think': 873,\n",
       " 'cockpit': 874,\n",
       " 'facing': 875,\n",
       " 'deck': 876,\n",
       " 'fuck': 877,\n",
       " 'settled': 878,\n",
       " 'whipped': 879,\n",
       " 'hugely': 880,\n",
       " 'extreme': 881,\n",
       " 'mi': 882,\n",
       " 'dry': 883,\n",
       " 'hospitality': 884,\n",
       " 'constructive': 885,\n",
       " 'mtgs': 886,\n",
       " 'uno': 887,\n",
       " 'split': 888,\n",
       " 'images': 889,\n",
       " 'fe': 890,\n",
       " 'timely': 891,\n",
       " 'american': 892,\n",
       " 'nearly': 893,\n",
       " 'confident': 894,\n",
       " 'overnight': 895,\n",
       " 'outfitted': 896,\n",
       " 'explore': 897,\n",
       " 'goddamn': 898,\n",
       " 'well': 899,\n",
       " 'conversations': 900,\n",
       " 'deceptive': 901,\n",
       " 'prices': 902,\n",
       " 'considered': 903,\n",
       " 'thingafteranother': 904,\n",
       " 'directional': 905,\n",
       " 'irmafromdallas': 906,\n",
       " 'warning': 907,\n",
       " 'worsttripofmylife': 908,\n",
       " 'lieflat': 909,\n",
       " 'ours': 910,\n",
       " 'focus': 911,\n",
       " 'ms': 912,\n",
       " 'k': 913,\n",
       " 'lousy': 914,\n",
       " 'dbfd': 915,\n",
       " 'thin': 916,\n",
       " 'southwestoliver': 917,\n",
       " 'bottom': 918,\n",
       " 'currently': 919,\n",
       " 'myvxexperience': 920,\n",
       " 'prove': 921,\n",
       " 'means': 922,\n",
       " 'aaron': 923,\n",
       " 'protected': 924,\n",
       " 'water': 925,\n",
       " 'noooooooooooooooooooooope': 926,\n",
       " 'attitude': 927,\n",
       " 'works': 928,\n",
       " 'wont': 929,\n",
       " 'buzz': 930,\n",
       " 'prevent': 931,\n",
       " 'ahead': 932,\n",
       " 'ru': 933,\n",
       " 'vf': 934,\n",
       " 'unhelpfulness': 935,\n",
       " 'funited': 936,\n",
       " 'thepoopqueen': 937,\n",
       " 'interview': 938,\n",
       " 'eq': 939,\n",
       " 'tammy': 940,\n",
       " 'rita': 941,\n",
       " 'place': 942,\n",
       " 'winston': 943,\n",
       " 'callback': 944,\n",
       " 'div': 945,\n",
       " 'having': 946,\n",
       " 'giants': 947,\n",
       " 'kl': 948,\n",
       " 'boards': 949,\n",
       " 'nxt': 950,\n",
       " 'gqebfk': 951,\n",
       " 'tasty': 952,\n",
       " 'moodlighting': 953,\n",
       " 'pennypincher': 954,\n",
       " ')': 955,\n",
       " 'crisis': 956,\n",
       " 'closet': 957,\n",
       " 'odd': 958,\n",
       " 'preference': 959,\n",
       " 'nocompensation': 960,\n",
       " 'affiliate': 961,\n",
       " 'step': 962,\n",
       " 'wednesday': 963,\n",
       " 'frequent': 964,\n",
       " 'tz': 965,\n",
       " 'refueling': 966,\n",
       " 'its': 967,\n",
       " 'elaborate': 968,\n",
       " 'hell': 969,\n",
       " 'grr': 970,\n",
       " 'rant': 971,\n",
       " 'appropriately': 972,\n",
       " 'highly': 973,\n",
       " 'vallarta': 974,\n",
       " 'oh': 975,\n",
       " 'takes': 976,\n",
       " 'feels': 977,\n",
       " 'charm': 978,\n",
       " 'failing': 979,\n",
       " 'correct': 980,\n",
       " 'run': 981,\n",
       " 'devalue': 982,\n",
       " 'baseball': 983,\n",
       " 'photography': 984,\n",
       " 'point': 985,\n",
       " 'resolving': 986,\n",
       " 'twtr': 987,\n",
       " 'und': 988,\n",
       " 'away': 989,\n",
       " 'fro': 990,\n",
       " 'dming': 991,\n",
       " 'belong': 992,\n",
       " 'jdvk': 993,\n",
       " 'msn': 994,\n",
       " 'piela': 995,\n",
       " 'damages': 996,\n",
       " 'intl': 997,\n",
       " 'paradise': 998,\n",
       " 'dumb': 999,\n",
       " 'information': 1000,\n",
       " ...}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_ok = data.text.apply(lambda x: [word_index.get(word, 0) for word in x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data_ok.iloc[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "maxlen = max(len(x) for x in data_ok)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "40"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxlen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_ok = keras.preprocessing.sequence.pad_sequences(data_ok.values, maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4726, 40)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_ok.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0, ..., 0, 0, 0])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.review.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = keras.Sequential()\n",
    "model.add(layers.Embedding(max_word, 50, input_length=maxlen))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.MaxPooling1D(3))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.GlobalAveragePooling1D())\n",
    "model.add(layers.Dense(1, activation='sigmoid'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding (Embedding)        (None, 40, 50)            355050    \n",
      "_________________________________________________________________\n",
      "conv1d (Conv1D)              (None, 40, 32)            11232     \n",
      "_________________________________________________________________\n",
      "max_pooling1d (MaxPooling1D) (None, 13, 32)            0         \n",
      "_________________________________________________________________\n",
      "conv1d_1 (Conv1D)            (None, 13, 32)            7200      \n",
      "_________________________________________________________________\n",
      "global_average_pooling1d (Gl (None, 32)                0         \n",
      "_________________________________________________________________\n",
      "dense (Dense)                (None, 1)                 33        \n",
      "=================================================================\n",
      "Total params: 373,515\n",
      "Trainable params: 373,515\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(optimizer=keras.optimizers.RMSprop(),\n",
    "              loss='binary_crossentropy',\n",
    "              metrics=['acc']\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\guanghua\\anaconda3\\envs\\tensor\\lib\\site-packages\\tensorflow\\python\\ops\\gradients_impl.py:112: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.\n",
      "  \"Converting sparse IndexedSlices to a dense Tensor of unknown shape. \"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 3780 samples, validate on 946 samples\n",
      "Epoch 1/10\n",
      "3780/3780 [==============================] - 7s 2ms/step - loss: 0.5581 - acc: 0.7272 - val_loss: 0.3557 - val_acc: 0.8805\n",
      "Epoch 2/10\n",
      "3780/3780 [==============================] - 0s 77us/step - loss: 0.2657 - acc: 0.9034 - val_loss: 0.2128 - val_acc: 0.9197\n",
      "Epoch 3/10\n",
      "3780/3780 [==============================] - 0s 80us/step - loss: 0.1718 - acc: 0.9344 - val_loss: 0.1948 - val_acc: 0.9292\n",
      "Epoch 4/10\n",
      "3780/3780 [==============================] - 0s 87us/step - loss: 0.1229 - acc: 0.9553 - val_loss: 0.1729 - val_acc: 0.9345\n",
      "Epoch 5/10\n",
      "3780/3780 [==============================] - 0s 85us/step - loss: 0.0957 - acc: 0.9656 - val_loss: 0.1703 - val_acc: 0.9376\n",
      "Epoch 6/10\n",
      "3780/3780 [==============================] - 0s 86us/step - loss: 0.0737 - acc: 0.9738 - val_loss: 0.2305 - val_acc: 0.9049\n",
      "Epoch 7/10\n",
      "3780/3780 [==============================] - 0s 81us/step - loss: 0.0524 - acc: 0.9828 - val_loss: 0.2402 - val_acc: 0.9218\n",
      "Epoch 8/10\n",
      "3780/3780 [==============================] - 0s 88us/step - loss: 0.0427 - acc: 0.9865 - val_loss: 0.2469 - val_acc: 0.9101\n",
      "Epoch 9/10\n",
      "3780/3780 [==============================] - 0s 85us/step - loss: 0.0345 - acc: 0.9894 - val_loss: 0.2667 - val_acc: 0.9218\n",
      "Epoch 10/10\n",
      "3780/3780 [==============================] - 0s 86us/step - loss: 0.0236 - acc: 0.9931 - val_loss: 0.2444 - val_acc: 0.9292\n"
     ]
    }
   ],
   "source": [
    "history = model.fit(data_ok, data.review.values, epochs=10, batch_size=128, validation_split=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = keras.Sequential()\n",
    "model.add(layers.Embedding(max_word, 50, input_length=maxlen))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.MaxPooling1D(3))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.Conv1D(32, 7, activation='relu', padding='same'))\n",
    "model.add(layers.GlobalAveragePooling1D())\n",
    "model.add(layers.Dense(1, activation='sigmoid'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(optimizer=keras.optimizers.RMSprop(),\n",
    "              loss='binary_crossentropy',\n",
    "              metrics=['acc']\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
